#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    void blackrack(vector<vector<int>>& res, vector<int>& nums, int first, int len)
    {
        if (first == len)
        {
            res.emplace_back(nums);
            return;
        }
        for (int i = first; i < len; ++i)
        {
            swap(nums[i], nums[first]);
            blackrack(res, nums, first + 1, len);
            swap(nums[i], nums[first]);
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        vector<vector<int>> res;
        blackrack(res, nums, 0, nums.size());
        return res;
    }
};
int main()
{
    vector<int> nums = { 1, 2, 3 };
    vector<vector<int>> res = Solution().permute(nums);
    for (const auto& nums : res)
    {
        for (const auto& num : nums)
            cout << num << " ";
        cout << endl;
    }
    return 0;
}